/*
 * Copyright (C) 2018 Zhejiang xiaominfo Technology CO.,LTD.
 * All rights reserved.
 * Official Web Site: http://www.xiaominfo.com.
 * Developer Web Site: http://open.xiaominfo.com.
 */

package com.lishiots.cloud.datacenter.middleware.common;

import cn.hutool.core.date.DateTime;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.UUID;

/***
 *
 * @since:datacenter-parent 1.0
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a> 
 * 2018/08/14 13:36
 */
@Component
public class GlobalMetaHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object id = getFieldValByName("id", metaObject);
        Object createDate=getFieldValByName("createTime",metaObject);
        if (id==null){
            setFieldValByName("id", UUID.randomUUID().toString().replaceAll("-",""),metaObject);
        }
        if (createDate==null){
            setFieldValByName("createTime",DateTime.now().toJdkDate(),metaObject);
        }


    }

    @Override
    public void updateFill(MetaObject metaObject) {
    }

}
